package com.adddeluser;

import com.commonfunction.CommFunction;
import com.databasefunction.AllDBFunction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteUser extends ActionSupport{
	
	private String userid,userrole;
	
	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if ((null != userrole) && ( userrole.equals("admin") || userrole.equals("superadmin"))) {
			
		}else
			return "unauthorised";
		
		AllDBFunction allDBFunction = new AllDBFunction();
		allDBFunction.deleteUser(userid);
		return "success";
	}
	
	@Override
	public void validate() {
		// TODO Auto-generated method stub
		userrole = (String) ActionContext.getContext().getSession().get("userrole");
		CommFunction commFunction = new CommFunction();
		AllDBFunction allDBFunction = new AllDBFunction();
		if (!allDBFunction.isuserexist(userid)) {
			addActionError("User not exist");
		}
	}
}
